#!/usr/bin/node

const fs  = require('fs'),
      http = require('http'),
      pic = process.argv[2];

let  data = fs.readFileSync(pic);

if(process.argv.length !==3){
  console.error('命令行参数格式：cmd fileName');
  process.exit(1);
}

try {
  var uri = data.toString('base64');
}catch(e) {
  console.error(e.message);
  process.exit(-1);
}

let html = `<html><head><title>uri</title></head><body><img src="data:image/jpg;base64,${uri}"/></body></html>`;

http.createServer((req,res) => {
  try{
    res.end(html);
  }catch(e){
    console.error(e);
  }
}).listen(8080);

